classdef EventLoader
%EVENTLOADER a class that loads a SCV event file
%   opens an event file, and can search for events. Requires a directory
%   and filename for the file. It reeds things int he proper log format.
%   Also takes in an ExperimentSetup file to determine the logformat that
%   is being used.

   properties
       FileName = '';
       Directory = '';
       Data;
       Events;
       Length;
       Experiment
       FileFormat = '%f,%f,%f,%f,%f,%f,%f,%s';
       
   end

   methods
       %constructor that has a directory, file, and experiment variables.
       %It opens this partiular file and reads all the data. it reads teh
       %numerical data, as well as the last Even column.
       
       function this = EventLoader(directory, file, experiment)
           this.Directory = directory;
           this.FileName = file;
           this.Experiment = experiment;
           this.FileFormat = this.Experiment.EventFileFormat;
           
           file = [this.Directory '/' this.FileName];
           [t,x,y,z,h,r,p,e] = textread(file, this.FileFormat);
           this.Data = [t,x,y,z,h,r,p];
           this.Events = e;
           this.Length = length(this.Data(:,1));
       end
       
       %searches through and returns a list of all events that are the same
       %type as its input variable event. it then returns a list of the
       %numerical values for each of these events
       function results = GetEvents(this,event)
           results=();
           index = 1;
           for j=1:this.Length
               if strcmp(this.Event(k,1), event)
                   results(index,:) = this.Data(k,:);
                   index = index+1;
               end
           end
       end
       
       %determines the last pointin event and gets its X coordinate
       function val = GetPointingX(this)
           val = 0;
           for j=length(this.Events):1
               if strcmp(this.Events(j), this.Experiment.PointingTask)
                   val = this.Data(this.Experiment.X,j);
                   return
               end
           end
       end
       %determines the last pointin event and gets its Y coordinate
       function val = GetPointingY(this)
           val = 0;
           for j=length(this.Events):1
               if strcmp(this.Events(j), this.Experiment.PointingTask)
                   val = this.Data(this.Experiment.Y,j);
                   return
               end
           end
       end
       
       %determines the last pointin event and gets its Heading
       function val = GetPointingH(this)
           val = 0;
           for j=length(this.Events):1
               if strcmp(this.Events(j), this.Experiment.PointingTask)
                   val = this.Data(this.Experiment.H,j);
                   return
               end
           end
       end
   end
end 
